<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>权限管理</title>

    <!-- 引入Bootstrap 5 CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">

    <!-- 自定义样式 -->
    <style>
        body {
            background-color: #f4f7fc;
            font-family: Arial, sans-serif;
            display: flex;
            min-height: 100vh;
            margin: 0;
        }

        /* 侧边栏样式 */
        .sidebar {
            width: 250px;
            background-color: #007bff;
            color: white;
            height: 100vh;
            position: fixed;
            top: 0;
            left: 0;
            padding-top: 20px;
            box-shadow: 2px 0px 5px rgba(0, 0, 0, 0.1);
        }

        .sidebar h2 {
            text-align: center;
            margin-bottom: 20px;
            font-size: 20px;
        }

        .sidebar a {
            display: block;
            padding: 12px;
            color: white;
            text-decoration: none;
            font-size: 16px;
        }

        .sidebar a:hover {
            background-color: #0056b3;
        }

        /* 页面主内容部分 */
        .main-content {
            margin-left: 250px;
            padding: 20px;
            flex-grow: 1;
        }

        h1 {
            text-align: center;
            color: #007bff;
            margin-bottom: 30px;
        }

        .table th, .table td {
            vertical-align: middle;
        }

        .table-responsive {
            overflow-x: auto;
        }

        .btn-custom {
            background-color: #007bff;
            color: white;
            border: none;
            padding: 8px 16px;
            font-size: 1rem;
            border-radius: 5px;
        }

        .btn-custom:hover {
            background-color: #0056b3;
            text-decoration: none;
        }

        .back-link {
            display: inline-block;
            margin-top: 20px;
            text-align: center;
            color: #007bff;
            font-size: 1.1rem;
        }

        .back-link:hover {
            color: #0056b3;
            text-decoration: none;
        }
    </style>
</head>

<body>

<!-- 侧边栏 -->
<div class="sidebar">
    <h2>超级管理员控制台</h2>
    <a href="/superAdmin/achievementReview">科研成果审核</a>
    <a href="/superAdmin/users">用户管理</a>
    <a href="/superAdmin/permissions/management">权限管理</a>
    <a href="/superAdmin/articleReview">文章审核</a>
    <a href="/logout">退出登录</a>
</div>

<!-- 页面主内容 -->
<div class="main-content">
    <div class="container">
        <h1>团队管理员权限管理</h1>

        <!-- 权限管理表格 -->
        <div class="table-responsive">
            <table class="table table-bordered table-striped table-hover">
                <thead class="table-light">
                <tr>
                    <th>ID</th>
                    <th>用户名</th>
                    <th>用户姓名</th>
                    <th>邮箱</th>
                    <th>权限</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <!-- 遍历所有管理员 -->
                <c:forEach var="admin" items="${admins}">
                    <tr>
                        <td>${admin.userId}</td>
                        <td>${admin.nickname}</td>
                        <td>${admin.name}</td>
                        <td>${admin.email}</td>
                        <td>
                            <!-- 根据权限列表判断并显示每个管理员的权限 -->
                            <c:forEach var="permission" items="${permissions}">
                                <!-- 判断权限是否属于该管理员 -->
                                <c:if test="${permission.userId == admin.userId}">
                                            <span>
                                                    ${permission.permissionType == 1 ? '团队管理' :
                                                            permission.permissionType == 2 ? '科研成果管理' :
                                                                    permission.permissionType == 3 ? '文章管理' :
                                                                            permission.permissionType == 4 ? '用户管理' :
                                                                                    permission.permissionType == 5 ? '在线交流' : ''}
                                            </span><br />
                                </c:if>
                            </c:forEach>
                        </td>
                        <td>
                            <!-- 编辑权限链接 -->
                            <a href="<c:url value='/superAdmin/users/${admin.userId}/modifyPermissions' />" class="btn btn-custom btn-sm">修改权限</a>
                        </td>
                    </tr>
                </c:forEach>
                </tbody>
            </table>
        </div>

    </div>
</div>

<!-- 引入Bootstrap 5 JS 和依赖 -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>

</body>

</html>
